<?php

namespace App\Http\Controllers\Excel;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Excel\Extensions\Exporter;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel;

class ExportController extends Controller
{
    public function list(){
        $data = Storage::allFiles('public/order');
        foreach ($data as $item){
            $extension = $this->get_extension($item);
            if($extension=='jpg'||$extension=='jpeg'){
                $name[] = $this->getArr($item);
            }
        }

       return Excel::download(new Exporter($name, $name),'用户列表.xlsx');
        //dd($regp);
    }
    protected function getArr($str){
        $splice = explode('  ',$str);
        preg_match('/(.*?)cm.?/', $splice[1], $matches, PREG_OFFSET_CAPTURE);
        $data =  explode('x',$matches[1][0]);
        $arr = [$str, '类型', 1, $data[0], $data[1],'否'];
        return $arr;
    }
    protected function  get_extension($file)
    {
        return pathinfo($file, PATHINFO_EXTENSION);
    }
}
